package edu.suda.xsap.controller;

import edu.suda.xsap.common.Result;
import edu.suda.xsap.dto.RegisterDto;
import edu.suda.xsap.entity.Register;
import edu.suda.xsap.service.RegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/register")
@Slf4j
public class RegisterController {
    @Autowired
    RegisterService registerService;

    @PostMapping("/save")
    public Result save(@RequestBody Register register) {
        registerService.save(register);
        return Result.success();
    }

    @GetMapping("/info")
    public Result get(@RequestParam("phone") String phone) {
        log.info("phone:"+phone);
        List<RegisterDto> registerDto = registerService.findByPhone(phone);
        return Result.success(registerDto);
    }

    @GetMapping("/getphone")
    public Result getphone(@RequestParam("name") String name, @RequestParam("password") String password) {
        log.info("name: " + name + " password: " + password);
        RegisterDto registerDto = registerService.findByNameandPassword(name, password);
            return Result.success(registerDto);
    }
}
